﻿using System;
using Platformer_Example.Controller.Interfaces;
using Platformer_Example.Controller.Map;
using Platformer_Example.Controller.Terrain.Castle;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Platformer_Example.Controller.Terrain
{
    public abstract class BaseLadder : ImageContainer, ICollidable
    {
        protected BaseLadder(TE_Vector2 position, TE_Vector2 size)
        {
            PositionGridBound = position;
            _collisionBox = new TE_Rectangle(0.125f, 0, 0.75f, size.Y).ToGridBound();
            AddSprite(size);
        }

        protected abstract void AddSprite(TE_Vector2 size);

        public static BaseLadder CreateLadder(MapCellData.TerrainType terrain, TE_Vector2 position, TE_Vector2 size)
        {
            switch (terrain)
            {
                case MapCellData.TerrainType.Castle:
                    return new CastleLadder(position, size);
                default:
                    throw new ArgumentOutOfRangeException("terrain");
            }
        }

        private readonly TE_Rectangle _collisionBox;
        public TE_Rectangle GetCollisionBox()
        {
            return _collisionBox;
        }

        public TE_Vector2 GetCollisionBoxPosition()
        {
            return AbsolutePosition;
        }

        public TE_Rectangle CollisionArea { get { return GetCollisionBox() + GetCollisionBoxPosition(); } }
    }
}